package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.RecordInfo;
import com.ruoyi.system.service.IRecordInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 投喂记录Controller
 * 
 * @author fxk
 * @date 2023-06-20
 */
@RestController
@RequestMapping("/system/record_info")
public class RecordInfoController extends BaseController
{
    @Autowired
    private IRecordInfoService recordInfoService;

    /**
     * 查询投喂记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:record_info:list')")
    @GetMapping("/list")
    public TableDataInfo list(RecordInfo recordInfo)
    {
        startPage();
        List<RecordInfo> list = recordInfoService.selectRecordInfoList(recordInfo);
        return getDataTable(list);
    }

    /**
     * 导出投喂记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:record_info:export')")
    @Log(title = "投喂记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RecordInfo recordInfo)
    {
        List<RecordInfo> list = recordInfoService.selectRecordInfoList(recordInfo);
        ExcelUtil<RecordInfo> util = new ExcelUtil<RecordInfo>(RecordInfo.class);
        util.exportExcel(response, list, "投喂记录数据");
    }

    /**
     * 获取投喂记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:record_info:query')")
    @GetMapping(value = "/{recordId}")
    public AjaxResult getInfo(@PathVariable("recordId") Long recordId)
    {
        return success(recordInfoService.selectRecordInfoByRecordId(recordId));
    }

    /**
     * 新增投喂记录
     */
    @PreAuthorize("@ss.hasPermi('system:record_info:add')")
    @Log(title = "投喂记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RecordInfo recordInfo)
    {
        return toAjax(recordInfoService.insertRecordInfo(recordInfo));
    }

    /**
     * 修改投喂记录
     */
    @PreAuthorize("@ss.hasPermi('system:record_info:edit')")
    @Log(title = "投喂记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RecordInfo recordInfo)
    {
        return toAjax(recordInfoService.updateRecordInfo(recordInfo));
    }

    /**
     * 删除投喂记录
     */
    @PreAuthorize("@ss.hasPermi('system:record_info:remove')")
    @Log(title = "投喂记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{recordIds}")
    public AjaxResult remove(@PathVariable Long[] recordIds)
    {
        return toAjax(recordInfoService.deleteRecordInfoByRecordIds(recordIds));
    }
}
